package xyz.chaobei.thread.pool;

import java.util.concurrent.*;

/**
 * @copyright (C), 2015-2020
 * @fileName: ThreadPoolTest
 * @author: MRC
 * @date: 2021/2/23 22:35
 * @description:
 */
public class ThreadPoolTest {

    public static void main(String[] args) {

        final int CORE_THREAD = 6;
        final int MAX_THREAD = 12;
        final long KEEP_ALIVE = 1L;
        final BlockingQueue<Runnable> TASK_QUEUE = new ArrayBlockingQueue<>(16);

        ThreadPoolExecutor executor = new ThreadPoolExecutor(CORE_THREAD, MAX_THREAD, KEEP_ALIVE,
                TimeUnit.SECONDS, TASK_QUEUE, new ThreadPoolExecutor.CallerRunsPolicy());

        for (int i = 0; i < 10; i++) {
            Runnable runnable = new RunnableTest("thread" + i);
            executor.execute(runnable);
        }

        executor.shutdown();
        System.out.println("executor is shutdown");

        while (!executor.isTerminated()) {

        }
        System.out.println("thread run over");
    }

}
